//
//  HMCustomServoceViewController.m
//  G05爱鲜蜂
//
//  Created by 小灰灰 on 16/10/16.
//  Copyright © 2016年 何源. All rights reserved.
//

#import "HMCustomServoceViewController.h"
#import "SVProgressHUD.h"
#import "HMQuestionViewController.h"
static NSString *ide = @"HMCustomServoceViewController";
@interface HMCustomServoceViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,weak)UITableView *servoceTableView;
@end

@implementation HMCustomServoceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"客服帮助";
    UITableView *servoceTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    [self.view addSubview:servoceTableView];
    _servoceTableView = servoceTableView;
    servoceTableView.delegate = self;
    servoceTableView.dataSource = self;
    [servoceTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:ide];
    servoceTableView.tableFooterView = [UIView new];
    servoceTableView.sectionHeaderHeight = 10;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ide forIndexPath:indexPath];
    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    if(indexPath.row == 0){
        cell.textLabel.text = @"客服电话：400-8844-1234";
    }
    else{
        cell.textLabel.text = @"常见问题";
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 0){
      //客服电话
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"400-8844-1234" message:nil preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *alertActionSure = [UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            //拨打电话
 
            [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel://40088441234"] options:@{@"":@1} completionHandler:^(BOOL success) {
                
            }];
            
        }];
        [alertController addAction:alertActionSure];
        UIAlertAction *alertActionChanel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alertController addAction:alertActionChanel];
        [self presentViewController:alertController animated:YES completion:nil];
    
    }
    else{
      //常见问题
        HMQuestionViewController *questionVC = [[HMQuestionViewController alloc] init];
        [self.navigationController pushViewController:questionVC animated:YES];
        
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
@end
